﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Dashboard.Models;
using Dashboard.Includes;
using System.Web.Routing;
using Dashboard.Languages.RU;

namespace Dashboard.Controllers
{
    public class StatDataProvider : IStatDataProvider
    {
        public String GetMenu()
        {
            string menu = MenuManager.Generate(
                new MenuItem("MixedDisplay", "Stat", Russian.MinuteStat, new RouteValueDictionary(new { displayType = RouterFragments.Stats.MinuteStat })),
                new MenuItem("MixedDisplay", "Stat", Russian.HourlyStat, new RouteValueDictionary(new { displayType = RouterFragments.Stats.HourlyStat })),
                new MenuItem("MixedDisplay", "Stat", Russian.DailyStat, new RouteValueDictionary(new { displayType = RouterFragments.Stats.DailyStat })),
                new MenuItem("MixedDisplay", "Stat", Russian.MonthlyStat, new RouteValueDictionary(new { displayType = RouterFragments.Stats.MonthlyStat }))
            );
            return menu;
        }

        public MixedPlotConstants GetPlotConstants(string displayType)
        {
            MixedPlotConstants plotConstants;

            string temp;
            temp = displayType.ToLower();
            if (temp.Length > 0)
            {
                temp = string.Format("{0}{1}", char.ToUpper(temp[0]), temp.Substring(1, temp.Length - 1 > 0 ? temp.Length - 1 : 0));
            }

            switch (temp)
            {
                case RouterFragments.Stats.MinuteStat:
                    plotConstants = new MixedPlotConstants(Russian.MinuteStatName, Russian.XAxisSeconds, (int)Count.Seconds * (int)Section.Second, (int)Section.Second, 2);
                    break;

                case RouterFragments.Stats.HourlyStat:

                    plotConstants = new MixedPlotConstants(Russian.HourlyStatName, Russian.XAxisMinutes, (int)Count.Minutes * (int)Section.Minute, (int)Section.Minute, 2);
                    break;

                case RouterFragments.Stats.DailyStat:
                    plotConstants = new MixedPlotConstants(Russian.DailyStatName, Russian.XAxisHours, (int)Count.Hours * (int)Section.Hour, (int)Section.Hour, 1);
                    break;

                case RouterFragments.Stats.MonthlyStat:
                    plotConstants = new MixedPlotConstants(Russian.MonthlyStatName, Russian.XAxisDays, (int)Count.Days * (int)Section.Day, (int)Section.Day, 1);
                    break;

                default:
                    return new Includes.MixedPlotConstants();
            }
            return plotConstants;
        }

        public List<List<byte>> GetModel(string displayType)
        {
            List<List<byte>> mixedModel;
            string temp;
            temp = displayType.ToLower();
            if (temp.Length > 0)
            {
                temp = string.Format("{0}{1}", char.ToUpper(temp[0]), temp.Substring(1, temp.Length - 1 > 0 ? temp.Length - 1 : 0));
            }

            switch (temp)
            {
                case RouterFragments.Stats.MinuteStat:
                    mixedModel = new List<List<byte>>(DataManager.Instance.GetSecondsAllCounter());
                    break;

                case RouterFragments.Stats.HourlyStat:
                    mixedModel = new List<List<byte>>(DataManager.Instance.GetMinutesAllCounter());
                    break;

                case RouterFragments.Stats.DailyStat:
                    mixedModel = new List<List<byte>>(DataManager.Instance.GetHoursAllCounter());
                    break;

                case RouterFragments.Stats.MonthlyStat:
                    mixedModel = new List<List<byte>>(DataManager.Instance.GetDaysAllCounter());
                    break;

                default:
                    return null;
            }
            return mixedModel;
        }

        public String GetMenu(String type)
        {
            return MenuManager.Generate(
            new MenuItem("Display", "Stat", Russian.MinuteStat, new RouteValueDictionary(new { type = type, displayType = RouterFragments.Stats.MinuteStat })),
            new MenuItem("Display", "Stat", Russian.HourlyStat, new RouteValueDictionary(new { type = type, displayType = RouterFragments.Stats.HourlyStat })),
            new MenuItem("Display", "Stat", Russian.DailyStat, new RouteValueDictionary(new { type = type, displayType = RouterFragments.Stats.DailyStat })),
            new MenuItem("Display", "Stat", Russian.MonthlyStat, new RouteValueDictionary(new { type = type, displayType = RouterFragments.Stats.MonthlyStat }))
            );
        }

        public List<byte> GetModel(String type, String displayType)
        {
            List<byte> model;
            String temp = type.ToUpper();

            int index = 0;
            switch (temp)
            {
                case RouterFragments.Type.RAM:
                    index = (int)Counter.RAM;
                    break;
                case RouterFragments.Type.CPU:
                    index = (int)Counter.CPU;
                    break;
                case RouterFragments.Type.HDD:
                    index = (int)Counter.HDD;
                    break;
                default:
                    return null;
            }

            temp = displayType.ToLower();
            if (temp.Length > 0)
            {
                temp = String.Format("{0}{1}", char.ToUpper(temp[0]), temp.Substring(1, temp.Length - 1 > 0 ? temp.Length - 1 : 0));
            }

            switch (temp)
            {
                case RouterFragments.Stats.MinuteStat:
                    model = DataManager.Instance.GetSeconds((Counter)index);
                    break;

                case RouterFragments.Stats.HourlyStat:
                    model = DataManager.Instance.GetMinutes((Counter)index);
                    break;

                case RouterFragments.Stats.DailyStat:
                    model = DataManager.Instance.GetHours((Counter)index);
                    break;

                case RouterFragments.Stats.MonthlyStat:
                    model = DataManager.Instance.GetDays((Counter)index);
                    break;

                default:
                    return null;
            }
            return model;
        }

        public String GetDisplayView(String displayType)
        {
            String displayView;
            String temp = displayType.ToLower();
            if (temp.Length > 0)
            {
                temp = String.Format("{0}{1}", char.ToUpper(temp[0]), temp.Substring(1, temp.Length - 1 > 0 ? temp.Length - 1 : 0));
            }

            switch (temp)
            {
                case RouterFragments.Stats.MinuteStat:
                    displayView = ViewNames.Minute;
                    break;

                case RouterFragments.Stats.HourlyStat:
                    displayView = ViewNames.Hour;
                    break;

                case RouterFragments.Stats.DailyStat:
                    displayView = ViewNames.Day;
                    break;

                case RouterFragments.Stats.MonthlyStat:
                    displayView = ViewNames.Month;
                    break;

                default:
                    return null;
            }
            return displayView;
        }
    }
}